import { Component, OnInit } from '@angular/core';
import { User } from 'src/app/domain/user';
import { AuthService } from '../../service/auth.service'
import {AdministrativeService} from '../../service/administrative.service'
/*

@Author:刘洋

@Date: 2018-12-12

@员工主界面功能实现

@Last Modified time: 2018-12-16
*/
@Component({
  selector: 'app-administrative-main',
  templateUrl: './administrative-main.component.html',
  styleUrls: ['./administrative-main.component.css']
})

export class AdministrativeMainComponent implements OnInit {
  public isVisible:boolean;
  date = new Date();
  user:User;
  
  constructor(private administrativeService:AdministrativeService) {
    this.user = {
      id: 0,
      user_name: null,
      name: null,
      age: 0,
      sex: null,
      department: null, //部门
      position: null, //职务
      annual_leave_length: null, //年假上限
      remain_annual_leave: null, //剩余年假
    };
  }
  ngOnInit() {
    this.getMe();
  }
  getMe(){
    var me = AuthService.getUserId();
    if(me == 0){
      alert("请先登录");
    }else{
    this.administrativeService.getUser(me)
    .subscribe(date=>this.user = date[0]);
    }
  }
  getNum() : number{
    return (Math.round(10000*this.user.remain_annual_leave/this.user.annual_leave_length)/100);
  }
}
